<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\common\facade\Builder;
use GuzzleHttp\Promise\Is;

//该文件为自动生成，请按需修改
class Usercoupon extends Base
{
    //所有定义变量均为演示，请根据实际需求更改

    //主键，默认为id
    protected string $pk = 'id';

    //主模型
    protected string $model = '\app\common\model\Usercoupon';

    //关联模型
    protected array $hasOne = ['user'];


    public function index(): string
    {
        
        $param = $this->request->get();
        //构建表格数据
        $table = Builder::Table()
            ->addColumn(['type' => 'checkbox', 'title' => '全选', 'fixed' => 'left'])
            ->addColumn(['field' => 'id', 'sort' => true, 'title' => 'ID', 'width' => 80])
            ->addColumn(['field' => 'title', 'title' => '标题', 'modify' => '2,input'])
            ->addColumn(['field' => 'code', 'title' => '领取会员', 'templet' => '#_userTpl', 'width' => 250])
            ->addColumn(['field' => 'money', 'title' => '金额', 'modify' => '2,input'])
            ->addColumn(['field' => 'sale_money', 'title' => '优惠金额', 'modify' => '2,input'])
            ->addColumn(['field' => 'create_time', 'title' => '创建时间'])
            ->addColumn(['field' => 'update_time', 'title' => '更新时间'])
            ->addColumn(['field' => 'status', 'title' => '状态','templet' => '#couponTpl',])
            ->addColumn(['fixed' => 'right', 'title' => '操作', 'align' => 'center', 'toolbar' => '#barDemo', 'width' => 200])
            ->addRightButtons(['delete'])
            ->addTopButtons(['deleteAll'])
            ->addSearch([
                ['uid', '会员编号/昵称/手机号', 'input', '', '\app\common\model\User', 'code|nickname|mobile,id'],
                ['title', '文章标题搜索', 'input', '', '', '', 'like']
            ]);
            
            if(isset($param['id'])){
                $table->addExtraMap(['coupon_id'=>$param['id']]);
            }
            return $table->fetch();
    }
}
